public class HourlyEmployee extends Employee {
    private double hourlyRate; // 时薪
    private double workHours; // 工作时长

    public HourlyEmployee(String name, String empId, double hourlyRate, double workHours) throws Exception {
        super(name, empId);
        this.hourlyRate = hourlyRate;
        // 异常处理：工作时长不合法（如负数、超过当月最大工时）
        if (workHours < 0 || workHours > 300) {
            throw new Exception("工作时长异常：合法范围是0-300小时");
        }
        this.workHours = workHours;
    }

    // 实现薪资计算（时薪×工时）
    @Override
    public double calculateSalary() {
        return hourlyRate * workHours;
    }

    // 生成工资条
    @Override
    public String generatePaySlip() {
        return "=== 工资条 ===\n" +
                "员工姓名：" + getName() + "\n" +
                "员工工号：" + getEmpId() + "\n" +
                "员工类型：普通员工\n" +
                "时薪：" + hourlyRate + "元\n" +
                "工作时长：" + workHours + "小时\n" +
                "本月薪资：" + calculateSalary() + "元";
    }
}